﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Text;

public partial class Login : System.Web.UI.Page
{
    ShopLaptopConnection conn;
    protected void Page_Load(object sender, EventArgs e)
    {
        conn = new ShopLaptopConnection();
        if (!IsPostBack)
        {
           
            

        }
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {

        Customer cus = conn.GetCustomerByUserPass(txtUsername.Text,txtPassword.Text);
        if (cus == null)
        {
            ShowPopUpMsg("Username or Password is not correct!");
            return;
        }
        Session["Customer"] = cus;
        FormsAuthentication.RedirectFromLoginPage(cus.CusName,true);
    }

    private void ShowPopUpMsg(string msg)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("alert('");
        sb.Append(msg.Replace("\n", "\\n").Replace("\r", "").Replace("'", "\\'"));
        sb.Append("');");
        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "showalert", sb.ToString(), true);
    }
    protected void lbtnShopCart_Click(object sender, EventArgs e)
    {
        if (Session["proID"] != null)
        {
            Response.Redirect("Cart.aspx");
        }
        Response.Redirect("CartEmpty.aspx");
    }
}
